/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2013.02.15
 */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forab(i, a, b) for (int i = (a); i <= (b); i++)

typedef int T;

const int M = 103;
const int inf = 10;

char s[M], w[M][M];
int n, sl, wl[M];
T g[M][M], f[M][M];

inline void relax( T &a, T b )
{
  a = min(a, b);
}

int main()
{
  assert(gets(s)), sl = strlen(s);
  assert(scanf("%d ", &n) == 1 && n <= M);
  forn(i, n)
  {
    assert(gets(w[i])), wl[i] = strlen(w[i]);
    forn(j, i)
      if (!strcmp(w[j], w[i]))
        i--, n--, j = i;
  }
  memset(f, inf, sizeof(g));
  forn(i, sl)
    f[i][0] = 0;
  for (int l = sl - 1; l >= 0; l--)
  {
    forn(i, n)
      if (s[l] == w[i][0])
      {
        const char *W = w[i];
        const int WL = wl[i];
        memset(&g[l], inf, sizeof(g[0]) * (sl - l));
        g[l][0] = 0;
        forab(len, 1, sl - l)
        {
          int m = l + len - 1;
          forn(j, WL - 1)
            if (g[m][j] <= M)
              for (int m1 = m + 1; m1 < sl; m1++)
                if (s[m1] == W[j + 1])
                  relax(g[m1][j + 1], g[m][j] + f[m + 1][m1 - m - 1]);
          relax(f[l][len], g[m][WL - 1] + 1);
        }
      }

    forab(len, 1, sl - l)
      forab(k, 1, len - 1)
        relax(f[l][len], f[l][k] + f[l + k][len - k]);
  }
  printf("%d\n", f[0][sl]);
  return 0;
}
                  